package com.acwing.partition11;

import java.io.*;
import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2021/12/22 10:47
 */
public class AC1072树的最长路径 {
    
    private static final int N = 10010;
    private static int[] h = new int[N], e = new int[N * 2], ne = new int[N * 2], w = new int[N * 2];
    private static int n, idx = 1, ans = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(reader.readLine());
        Arrays.fill(h, -1);
        for (int i = 0; i < n - 1; i++) {
            String[] ss = reader.readLine().split(" ");
            int a = Integer.parseInt(ss[0]), b = Integer.parseInt(ss[1]), c = Integer.parseInt(ss[2]);
            add(a, b, c);
            add(b, a, c);
        }
        dfs(1, -1);
        writer.write(ans + "\n");
        writer.flush();
    }

    private static int dfs(int u, int parent) {
        int d1 = 0, d2 = 0;
        for (int i = h[u]; i != -1; i = ne[i]) {
            int v = e[i];
            if (v == parent) continue;
            int res = dfs(v, u) + w[i];
            if (res >= d1) {
                d2 = d1;
                d1 = res;
            } else if (res > d2) {
                d2 = res;
            }
        }
        ans = Math.max(d1 + d2, ans);
        return d1;
    }

    private static void add(int a, int b, int c) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx;
        w[idx++] = c;
    }
}
